<template>
  <div class="dataStaticDetail">
    <div class="pageHeaders">
      <div class="page-header">
        <div class="page-header__left">
          <i class="el-icon-arrow-left" @click="goBack"></i>
          <div class="page-header__title">数据统计</div>
        </div>
      </div>
      <div>
        <el-button
          size="small"
          type="primary"
          v-show="this.$route.query.currentName == '2'"
          v-has="'M1110002'"
          @click="exportFile"
          >导出</el-button
        >
        <el-button
          size="small"
          type="primary"
          v-show="this.$route.query.currentName == '3'"
          v-has="'M1110003'"
          @click="exportFile"
          >导出</el-button
        >
        <el-button
          size="small"
          type="primary"
          v-show="this.$route.query.currentName == '4'"
          v-has="'M1110004'"
          @click="exportFile"
          >导出</el-button
        >
        <el-button
          size="small"
          type="primary"
          v-show="this.$route.query.currentName == '5'"
          v-has="'M1110005'"
          @click="exportFile"
          >导出</el-button
        >

        <el-button size="small" type="primary" @click="goBack">关闭</el-button>
      </div>
    </div>
    <el-card class="statisticsDataTable">
      <el-row type="flex" class="row-bg" justify="end"> </el-row>
      <el-table
        border
        height="650"
        :data="statisticsData"
        class="statisticsData"
        v-loading="statisticsDataLoading"
        style="width: 100%"
        :cell-style="{ textAlign: 'center', height: '60px' }"
        :header-cell-style="{ textAlign: 'center', height: '50px', backgroundColor: '#FFFFFF' }"
      >
        <el-table-column prop="feedBackNumber" sortable label="反馈ID" width="180">
          <template slot-scope="scope">
            <span @click="tofeedBack(scope.row)" class="link-type">{{ scope.row.feedBackNumber }} </span>
          </template>
        </el-table-column>

        <el-table-column prop="productName" label="所属产品" width="180" sortable> </el-table-column>
         <el-table-column prop="taskNumber" sortable v-if="this.$route.query.type == 7" label="任务ID" min-width="80">
          <template slot-scope="scope">
            <span @click="getTaskDetail(scope.row)" class="link-type">{{ scope.row.taskNumber }} </span>
          </template>
        </el-table-column>
        <el-table-column prop="marketProjectName" label="所属营销项目名称" sortable> </el-table-column>
        <el-table-column prop="feedBackSource" label="反馈来源" sortable> </el-table-column>
        <el-table-column prop="title" label="标题" sortable>
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <div class="titles">标题: {{ scope.row.title }}</div>
              <div slot="reference" class="name-wrapper">
                <span size="medium">{{ scope.row.title | filterWords }}</span>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column sortable prop="designatorUserName" label="当前指派人"> </el-table-column>
      </el-table>
    </el-card>

    <!-- 控制数据展示数量的分页器 -->
    <div class="paginationClock">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :total="totalNumber"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import FilterTrans from '../../utils/paramsFiler'
import { DataStatistics } from '../../api/dataStatistics/server'
import { setTimeout } from 'timers'
export default {
    name: 'dataStaticDetail',
    components: {},
    data() {
        const EFilterOprator = FilterTrans.EFilterOprator
        return {
            queryinfo: {
                pageIndex: 1,
                pageRow: 50
            },
            page: 1,
            pageSize: 50,
            totalNumber: null,
            searchCondition: [
                {
                    field: 'name',
                    operator: EFilterOprator.Equal
                },
                {
                    field: 'meetingState',
                    operator: EFilterOprator.Equal
                }
            ],
            statisticsData: [],
            statisticsDataLoading: false
        }
    },
    filters: {
        filterWords(val) {
            if (val) {
                if (val.length >= 40) {
                    return val.substring(0, 20) + '...'
                } else {
                    return val
                }
            } else {
                return ''
            }
        }
    },
    mounted() {
        this.searchTable()
    },

    methods: {
        async FeedBackC1DurationDetail(_data) {
            try {
                let result = null
                if (_data.data.ctype == '1') {
                    result = await DataStatistics.FeedBackC1DurationDetail(_data)
                } else {
                    result = await DataStatistics.FeedBackC2DurationDetail(_data)
                }

                if (result.success) {
                    this.C1tableLoading = true
                    setTimeout(() => {
                        this.C1table = result.data
                        this.C1tableLoading = false
                    }, 1000)
                }
            } catch (err) {
                console.log(err)
            }
        },
        // 表格初始化方法
        searchTable() {
            const parmars = {
                data: JSON.parse(this.$route.query.data),
                markProjectId: this.$route.query.markProjectId,
                productId: this.$route.query.productId,
                queryDate: this.$route.query.queryDate,
                type: this.$route.query.type,
                page: this.page,
                pageSize: this.pageSize
            }
            this.GetFeedBackDetial(parmars)
        },
        // 表格初始化接口
        async GetFeedBackDetial(_data) {
            console.log('_data', _data)
            try {
                let result = null
                if (_data.type == 7) {
                    _data.closeFeedBack = true
                    result = await DataStatistics.GetFeedBackTaskDetail(_data)
                } else if (_data.type == 'FEEDBACK_TABLE_DURATION') {
                    console.log(_data)
                    _data.data.page = this.page
                    _data.data.pageSize = this.pageSize
                    if (_data.data.ctype == '1') {
                        result = await DataStatistics.FeedBackC1DurationDetail(_data.data)
                    } else if (_data.data.ctype == '2') {
                        result = await DataStatistics.FeedBackC2DurationDetail(_data.data)
                    } else {
                        result = await DataStatistics.GoBackCountDetail(_data.data)
                    }
                } else {
                    result = await DataStatistics.GetFeedBackDetial(_data)
                }

                if (result.success) {
                    this.statisticsDataLoading = true

                    if (result.data && result.data.data.length > 0) {
                        setTimeout(() => {
                            this.statisticsDataLoading = false
                            this.statisticsData = result.data.data
                            this.totalNumber = result.data.total
                        }, 1000)
                    } else {
                        setTimeout(() => {
                            this.statisticsDataLoading = false
                            this.statisticsData = []
                            this.totalNumber = 0
                        }, 1000)
                    }

                    // this.drawCharts();
                }
            } catch (err) {
                console.log(err)
            }
        },
        // 分页切换事件
        handleSizeChange(_val) {
            this.pageSize = _val
            this.searchTable()
        },
        // 分页点击事件
        handleCurrentChange(_val) {
            this.page = _val
            this.searchTable()
        },
        // 搜索点击
        searchClick() {
            this.filter = FilterTrans.buildPageRequest(this.overdueMettingForm, this.searchCondition)
            this.filter.orderConditions = [
                {
                    sortDirection: 'Ascending',
                    sortField: 'id'
                }
            ]
        },
        // 返回
        goBack() {
            this.$router.go(-1)
        },
        // 导出
        exportFile() {
            const parmars = {
                data: JSON.parse(this.$route.query.data),
                markProjectId: this.$route.query.markProjectId,
                productId: this.$route.query.productId,
                queryDate: this.$route.query.queryDate,
                type: this.$route.query.type,
                page: this.page,
                pageSize: this.pageSize
            }
            console.log('parmars', parmars)
            this.ExportStatistics(parmars)
        },
        // 导出会议记录
        async ExportStatistics(_data) {
            try {
                // FeedBackTaskExport
                let result = null
                if (_data.type == 7) {
                    _data.closeFeedBack = true
                    result = await DataStatistics.FeedBackTaskExport(_data)
                } else if (_data.type == 'FEEDBACK_TABLE_DURATION') {
                    if (_data.data.ctype == '1') {
                        result = await DataStatistics.FeedBackC1DurationExport(_data.data)
                    } else if (_data.data.ctype == '2') {
                        result = await DataStatistics.FeedBackC2DurationExport(_data.data)
                    } else {
                        result = await DataStatistics.GoBackCountDetailExport(_data.data)
                    }
                } else {
                    result = await DataStatistics.ExportStatistics(_data)
                }
                console.log(result)
            } catch (err) {
                console.log(err)
                this.$message.error(err)
            }
        },
        // 跳转反馈详情
        tofeedBack(row) {
            console.log(row)
            this.$router.push({
                path: 'Details?id=' + row.feedBackId
            })
        },
        getTaskDetail(row) {
            console.log(row)
            this.$router.push({
                path: 'taskDetail?id=' + row.taskNumber
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.dataStaticDetail {
  padding: 30px;
  overflow: auto;
  box-sizing: border-box;
  .pageHeaders {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 30px;
    box-sizing: border-box;
    width: 100%;
    height: 60px;
    background: #ffffff;
    box-shadow: 0px 2px 5px 0px rgba(152, 160, 179, 0.2);
    border-radius: 5px;
    .headers {
      line-height: 24px;
      font-size: 15px;
    }
    .page-header {
      display: flex;
      line-height: 24px;
      .page-header__left {
        display: flex;
        cursor: pointer;
        margin-right: 40px;
        position: relative;
      }
      .page-header__title {
        font-size: 15px;
        font-weight: 500;
      }
    }
    .page-header__left .el-icon-arrow-left {
      font-size: 18px;
      margin-right: 6px;
      align-self: center;
      &:hover {
        color: #3579e0;
        cursor: pointer;
      }
    }
  }
  .statisticsDataTable {
    height: 706px;
    margin-top: 30px;
    padding: 30px;
    // padding-right: 20px;
    box-sizing: border-box;
    overflow: hidden;
    background-color: #ffffff;
    ::v-deep .el-card__body {
      padding: 0;
    }
  }
  .paginationClock {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 25px 0;
    ::v-deep .el-input__inner {
      width: 100%;
    }
  }
}

.link-type,
.link-type:focus {
  color: rgb(32, 160, 255);
  cursor: pointer;
  text-decoration: underline;
  &:hover {
    color: #337ab7;
  }
}
// /*滚动条样式*/
// ::v-deep .el-table--scrollable-y .el-table__body-wrapper::-webkit-scrollbar {
//   /*滚动条整体样式*/
//   width: 10px;
//   height: 32px;
// }
// ::v-deep .el-table--scrollable-y .el-table__body-wrapper::-webkit-scrollbar-thumb {
//   /*滚动条里面小方块*/
//   background: transparent;
// }
// ::v-deep .el-table--scrollable-y .el-table__body-wrapper::-webkit-scrollbar-track {
//   /*滚动条里面轨道*/
//   border-radius: 0;
//   background: transparent;
// }
::v-deep .el-table td,
.el-table th {
  padding: 0;
}
::v-deep .el-table th {
  background-color: #f6f6f6 !important;
}
::v-deep .el-table th {
  font-size: 14px;
  color: #3579e0;
  font-weight: 400;
}
::v-deep .el-table th.gutter {
  display: none;
}
.titles {
  max-width: 300px;
}
</style>
